package com.yiguo.logistics.web;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.R.integer;
import android.R.string;
import android.util.Log;
import android.widget.Toast;

public class WSHelper
{
  public WSHelper(String _Url)
  {
	  Url = _Url;
      androidHttpTransport = new HttpTransportSE(Url);
      androidHttpTransport.debug = true;
  }

  private String NameSpace = "http://tempuri.org/"; // ����ռ�Ĭ��Ϊ������ø�
  private String Url; 
  //= "http://172.17.6.64:10000/Service1.asmx"; // WebService������ַ
  //private String MethodName="CheckCode";//������
  //private String SoapAction = "http://tempuri.org/CheckCode"; // ����ռ�/������
 
  private SoapObject request = null;
  private SoapPrimitive result = null; // Ҫע��result����
  private SoapSerializationEnvelope envelope = null;
  private HttpTransportSE androidHttpTransport = null;

  public String GetDataFromWebService(String MethodName, HashMap<String,String> map)
  {
	request = new SoapObject(NameSpace, MethodName); 
    
	Iterator<Entry<String,String>> entrySetIterator=map.entrySet().iterator();
	while(entrySetIterator.hasNext())
	{
	  Entry<String,String> entry=entrySetIterator.next();
	  request.addProperty(entry.getKey(),entry.getValue());
	}
	
	
	envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
	envelope.dotNet = true;
	envelope.setOutputSoapObject(request);
	envelope.bodyOut = request;
	try
	{
	  androidHttpTransport.call(NameSpace+MethodName, envelope);
	  result = (SoapPrimitive)envelope.getResponse();
	}
	catch (Exception e)
	{
	  Log.e("ERROR", "WebService Failed", e);
	  e.printStackTrace();
	}
	return result.toString();
  }
}
